<template>
  <div class="category">
    <!-- 顶部搜索 -->
    <van-search
      v-model="value"
      @click="tosearch"
      placeholder="请输入搜索商品关键词"
    />
    <!-- 侧边导航 -->
    <div class="con">
      <van-sidebar v-model="activeKey">
        <van-sidebar-item
          @click="change(item.id)"
          v-for="item in leftList"
          :key="item.id"
          :title="item.name"
        />
      </van-sidebar>
      <div class="right-con">
        <img class="banner" :src="rightData.banner_url" alt="" />
        <h3>--- {{ rightData.name }}分类 ----</h3>
        <div class="goodsList">
          <div
            @click="
              tocategorysort(rightData.name, rightData.id, item.name, item.id)
            "
            class="item"
            v-for="item in rightData.subList"
            :key="item.id"
          >
            <img class="img" :src="item.wap_banner_url" alt="" />
            <p>{{ item.name }}</p>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { indexaction, currentaction } from "@/api/category/index";
export default {
  components: {},

  data() {
    return {
      value: "",
      activeKey: 0,
      leftList: [],
      rightData: [],
      leftId: 1005000,
    };
  },

  created() {
    indexaction().then((res) => {
      // console.log(res);
      this.leftList = res.categoryList;
    });
    currentaction({ id: this.leftId }).then((res) => {
      // console.log(res.data.currentOne);
      this.rightData = res.data.currentOne;
    });
  },

  mounted() {},

  methods: {
    // 到搜索页面
    tosearch() {
      this.$router.push({ name: "search" });
    },
    // 到分类页面
    tocategorysort(bigname, bigid, smallname, smallid) {
      this.$router.push({
        name: "categorysort",
        params: {
          name1: bigname,
          id1: bigid,
          name2: smallname,
          id2: smallid,
        },
      });
      console.log(bigname, bigid, smallname, smallid);
    },
    change(id) {
      console.log(id);
      this.leftId = id;
      currentaction({ id: this.leftId }).then((res) => {
        console.log(res.data.currentOne);
        this.rightData = res.data.currentOne;
      });
    },
  },

  computed: {},

  watch: {},
};
</script>

<style scoped lang='less'>
.van-search {
  margin-bottom: 4px;
}
.con {
  display: flex;
  justify-content: space-between;
  margin-top: 4px;
  // background-color: #fff;
  padding: 30px 0;
  padding-top: 0;

  .right-con {
    width: 280px;
    padding: 0 10px;
    float: left;
    .banner {
      width: 260px;
      margin-top: 10px;
    }
    h3 {
      margin: 10px auto;
    }
    .goodsList {
      width: 250px;
      display: flex;
      justify-content: space-between;
      margin: 0 auto;
      flex-wrap: wrap;
      .item {
        width: 80px;
        height: 89px;
        margin-top: 10px;
        .img {
          width: 72px;
          height: 72px;
          margin: 0 auto;
        }
      }
    }
  }
}
.category {
  width: 375px;
  height: 100%;
  background-color: #fff;
}
</style>